package com.briup.product_source.controller;


import com.briup.product_source.pojo.ManagerFenceHouse;
import com.briup.product_source.pojo.ManagerHurdles;
import com.briup.product_source.pojo.ext.ManagerHurdlesExt;
import com.briup.product_source.result.Result;
import com.briup.product_source.service.HurdlesService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "栏圈管理模块")
@RestController
@RequestMapping("/hurdle")
public class HurdleController {


    @Autowired
    private HurdlesService hurdlesService;


    @ApiOperation("分页多条件查询栏圈信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页大小", defaultValue = "10", required = true),
            @ApiImplicitParam(name = "hName",value = "栏圈名称"),
            @ApiImplicitParam(name = "fghName",value = "栏舍名称"),
            @ApiImplicitParam(name = "hMax",value = "栏圈容量"),
            @ApiImplicitParam(name = "hEnable",value = "是否可用")
    })
    @GetMapping
    public Result queryAllAndPage(Integer pageNum,Integer pageSize,String hName, Integer hMax, String fhName, String hEnable){
        PageInfo <ManagerHurdlesExt> pageInfo = hurdlesService.queryAllAndPage(pageNum,pageSize,hName,hMax,fhName,hEnable);
        return Result.success(pageInfo);
    }

    @ApiOperation("查询栏圈中所有的栏圈容量接口")
    @GetMapping("/queryAllMax")
    public Result queryAllMax() {
        return Result.success(hurdlesService.findAllMax());
    }


    @ApiOperation("禁用或启用栏圈接口")
    @PutMapping("/{hId}/{hEnable}")
    public Result changeStatus(@PathVariable String hId,@PathVariable String hEnable){
        hurdlesService.changeStatus(hId,hEnable);
        return Result.success();
    }


    @ApiOperation("批量禁用或启用栏圈接口")
    @PutMapping
    public Result changeStatus(@RequestBody List<Map<String,String>> ids){
        hurdlesService.changeStatusByChoice(ids);
        return Result.success();
    }

    @ApiOperation("添加或修改接口")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ManagerHurdles managerHurdles){
        hurdlesService.insertOrUpdate(managerHurdles);
        return Result.success();
    }


    @ApiOperation("删除功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hId", value = "栏圈编号", required = true)
    })
    @DeleteMapping("/deleteById/{hId}")
    public Result deleteById(@PathVariable String hId){
        hurdlesService.deleteById(hId);
        return Result.success();
    }


    @ApiOperation("查询可用栏圈")
    @GetMapping("/queryAllEnable")
    public Result queryAllEnable(){
        return Result.success(hurdlesService.queryAllEnable());
    }
}
